package beanstao.util.type.base;

import java.util.Collection;
import java.util.Map;

import beanstao.util.Util;
import beanstao.util.exception.technical.util.reflect.FailToCastObjectException;
import beanstao.util.type.Castor;

@SuppressWarnings({ "unchecked", "rawtypes" })
public class Collection2Map extends Castor<Collection, Map>
{

	@Override
	public Map cast(Collection src, Class<?> toType, String... args) throws FailToCastObjectException
	{
		if ((null == args) || (args.length == 0))
			throw Util.makeThrow(FailToCastObjectException.class, "For the elements in Collection %s, castors don't know which one is the key field.", src.getClass().getName());
		return Util.collection2map((Class<Map<Object, Object>>) toType, src, args[0]);
	}

}
